/*
 * Copyright (C) 2010 TopCoder Inc., All Rights Reserved.
 */
package com.hercules.android.receiver.commands;

import org.json.JSONObject;

import com.hercules.android.receiver.ConnectionManagerException;
import com.hercules.android.receiver.Receiver;

/**
 * <p>
 * This command handler class will handle the RESTART command.
 * </p>
 * 
 * @author TCSASSEMBER
 * @version 1.0
 */
public class XRERestartCommandHandler extends XRECommandHandler {
    /**
     * Create a new <code>XRERestartCommandHandler</code> with the
     * <code>Receiver</code> instance.
     * 
     * @param receiver
     *            the <code>Receiver</code> instance.
     * @throws IllegalArgumentException
     *             if argument is null
     */
    public XRERestartCommandHandler(Receiver receiver) {
        super(receiver);
    }

    /**
     * Process the RESTART command message.
     * 
     * @param message
     *            the command message to be processed.
     * @throws XRECommandHandlerException
     *             if any other error occurs
     */
    public void processCommand(JSONObject message) throws XRECommandHandlerException {
        try {
            // send onConnect event
            receiver.getConnectionManager().connect();
        } catch (ConnectionManagerException e) {
            throw new XRECommandHandlerException("Error occurs when reconnecting to server.", e);
        }
    }

}
